<?php


namespace app\api\controller;

use app\api\service\QrcodeServer;
use app\api\service\WxpayService;

class Wxpay extends Common
{
    /**
     * 微信扫码支付接口
     * 直接输出二维码 + 生成二维码图片文件
     * User: wufeng
     * Date: 2020/04/16.
     */
    public function wxsmpay()
    {
        $data = $this->request->param();
        $res = (new WxpayService())->wxsmPay($data);
        if ('SUCCESS' === $res['result_code'] && 'SUCCESS' === $res['return_code'] && 'OK' === $res['return_msg']) {
            $this->success('生成收款二维码成功', '', ['url' => $res['code_url']]);
        } else {
            $this->error($res['msg'], '', '', 1);
        }
    }

	/**
	 * User: wufeng
	 * Date: 2020/04/17
	 *
	 * @return \think\response\View
	 * @throws \Endroid\QrCode\Exception\InvalidPathException
	 * @throws \Endroid\QrCode\Exception\InvalidWriterException
	 */
    public function payflow()
    {
        $url = input('img');
        // 自定义二维码配置
        $config = [
            'title' => true,
            'title_content' => '校务帮',
            'logo' => true,
            'logo_url' => './education/images/wechat.jpg',
            'logo_size' => 80,
        ];

        // 直接输出
        $qr_url = $url;
        $qr_code = new QrcodeServer($config);
        $qr_img = $qr_code->createServer($qr_url);
        $imageString = base64_encode($qr_img);
        $img = 'data:image/jpg;base64,'.$imageString;
        $this->assign('url', $img);

        return view();
    }
}
